var router = require('koa-router')();

var sign=require('../utils/sign')
var wx=require('../wx/index')

router.get('/', function (ctx) {
  
   ctx.render('index', {
    title: 'Hello World Koa!'
  });
});

router.get('/shunde',async function (ctx) {
  console.log('shundeshunde')
  var wechatApi=wx.getWechat()
  var data=await wechatApi.fetchAccessToken()
  var access_token=data.access_token
  var ticketData=await wechatApi.fetchTicket(access_token)
  var ticket=ticketData.ticket
  var url='http://'+ctx.header.host+ctx.url
  console.log('ctx.url',ctx.request)
  console.log('sign-into',ticket,url)
  var params=sign(ticket,url)
   console.log('ign-out',params)  
   await  ctx.render('index',params);
});

module.exports = router;
